<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use App\Model\AdminLogsModel;
use App\Model\AdminRolesModel;

//权限表
class AdminNodeModel extends Model
{
    //定义一个表名
    protected $table = 'admin_node';
    //定义主键
    protected $primaryKey = 'id';

    // const USER_TYPE = [
    //     ['type'=>1,'name'=>'用户管理'],
    //     ['type'=>2,'name'=>'财务管理'],
    //     ['type'=>3,'name'=>'文章管理'],
    //     ['type'=>4,'name'=>'配置管理'],
    //     ['type'=>5,'name'=>'管理员管理']
    // ];

    //关联角色
    public function roles()
    {
        return $this->belongsToMany(AdminRolesModel::class,'admin_node_role','node_id','role_id');
    }

    // //所有权限
    // public function listAll()
    // {
    //     $list = AdminNodeModel::USER_TYPE;
    //     foreach ($list as $k => $v) {
    //         $list[$k]['son'] = $this->where('type',$v['type'])->get()->toArray();
    //     }
    //     return $list;
    // }
}
